Skip to content

Latest commit

 

History

History

08 PyQt6 exe

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

PyQt6 exe

Once you have a PyQt6 application, you want to compile your Python source code into a standalone executable. Furthermore, you normally want to create an installer so your users can easily set up your app.

This example uses fbs to create a standalone executable and an installer for the text editor in example 07.

PyQt6 exe installer Installer for a PyQt6 Mac application

You can find a modified version of the "old" main.py in src/main/python/main.py. It only has a few extra lines:

We import fbs's ApplicationContext:

from fbs_runtime.application_context.PyQt6 import ApplicationContext

Further down, we instantiate it:

appctxt = ApplicationContext()

We no longer need to create a QApplication. This is done automatically by fbs.

The editor's About dialog shows an icon:

QDialog example

This is done in the original code as follows:

text = "...<img src=icon.svg>..."

The new code however needs to be more flexible with regard to the icon's path. When running from source, the icon lies in src/main/resources/base/icon.svg. When running on the user's system however, it lies in the installation directory.

To handle this, the new code uses fbs's ApplicationContext.get_resource(...) method:

text = "...<img src=%r>..." % appctxt.get_resource("icon.svg")

This automatically handles the different possible locations of the image.

Because we didn't create the QApplication ourselves, we finally use the following call instead of only app.exec():

appctxt.app.exec()

To run this example yourself, you need fbs installed as per the instructions here. Then, you can do use the following command to run the text editor:

fbs run

The following command then compiles the Python source code into a standalone executable in your target/ directory:

fbs freeze

Finally, the following creates an installer that you can distribute to other people:

fbs installer

Please note that this last command requires that you have NSIS installed and on your PATH on Windows, or fpm on Linux.